package com.linjacy.httpproject.response;

import lombok.Data;

import java.util.HashMap;

@Data
public class R<T> extends HashMap{

    public static final int SUCCESS_CODE = 200;
    public static final int ERROR_CODE = 500;
    public static final String SUCCESS_MSG = "success";
    public static final String ERROR_MSG = "系统错误";

    public R(int code, String msg){
        this.put("code", code);
        this.put("msg", msg);
    }
    public R(){}

    public static R success(){
        return new R(SUCCESS_CODE, SUCCESS_MSG);
    }

    public static R success(String msg){
        return new R(SUCCESS_CODE, msg);
    }

    public static R error(){
        return new R(ERROR_CODE, ERROR_MSG);
    }

    public static R error(String msg){
        return new R(ERROR_CODE, msg);
    }

    public R put(String key, T data){
        super.put(key, data);
        return this;
    }

}
